package org.xyz.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.xyz.dao.UserMapper;
import org.xyz.entity.User;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

@Service
@Slf4j
public class MemberService {
    @Autowired
    UserMapper userMapper;

    @Scheduled(cron = "0 0 0 * * ?") // 每天凌晨0点执行
    public void reduceMembershipDays() {
        List<User> users = userMapper.selectList(null);
        users.stream().forEach(user -> {
            Integer leftDays = user.getLeftDays();
            if (leftDays != null && leftDays > 0) {
                user.setLeftDays(leftDays-1);
                /////////log.info(user.toString(), user.getLeftDays());
                userMapper.updateById(user);
            }
        });
    }
}
